//
//  RecommendViewController.m
//  HumorousScripts
//
//  Created by 李欢 on 15/6/15.
//  Copyright (c) 2015年 李欢. All rights reserved.
//

#import "RecommendViewController.h"
#import "SANetWorkingTask.h"
#import <UIImageView+WebCache.h>
#import "RecTableViewCell.h"
#import "Recommend.h"
#import "firstViewController.h"
#import "secondViewController.h"
#import "thirdViewController.h"

#define Width [UIScreen mainScreen].bounds.size.width
#define Height [UIScreen mainScreen].bounds.size.height


@interface RecommendViewController ()<UITableViewDataSource,UITableViewDelegate>
//创建tavleView
@property (nonatomic, retain) UITableView * tableView;
//创建大数组
@property (nonatomic, retain) NSMutableArray * tableArray;
@end

@implementation RecommendViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.tableArray = [NSMutableArray array];
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    
        [self creatView];
        [self.tableView reloadData];
    
}

//创建tableView
-(void)creatView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height - 64/667.0*Height) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 188/667.0*Height;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:self.tableView];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    重定池
    static NSString * cellIdentify = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentify];
    }
    
    if (indexPath.row == 0) {
        UIImage * aimage = [UIImage imageNamed:@"03.jpg"];
        UIImageView * aview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
        [aview setImage:aimage];
        [cell setBackgroundView:aview];

    } else if (indexPath.row == 1){
        UIImage * bimage = [UIImage imageNamed:@"01.jpg"];
        UIImageView * bview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [bview setImage:bimage];
        [cell setBackgroundView:bview];
        
    } else if (indexPath.row == 2) {
        UIImage * cimage = [UIImage imageNamed:@"02.jpg"];
        UIImageView * cview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [cview setImage:cimage];
        [cell setBackgroundView:cview];
    }
   
    return cell;
}


#pragma mark -
#pragma mark 点击协议

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //使cell不会保持持续选中状态
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        firstViewController * first = [[firstViewController alloc]init];
        [self.navigationController pushViewController:first animated:YES];
    } else if(indexPath.row == 1) {
        secondViewController * second = [[secondViewController alloc]init];
        [self.navigationController pushViewController:second animated:YES];
    } else if (indexPath.row == 2) {
        thirdViewController * third = [[thirdViewController alloc]init];
        [self.navigationController pushViewController:third animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
